l,m = tuple(map(int,input().split()))
a = [1]*(l+1)
for i in range(m):
    start,end = tuple(map(int,input().split()))
    a[start:end+1] = [0]*(end-start+1)
print(a.count(1))